//
//  NSArray+MM_AY.m
//  MallManage_IOS
//
//  Created by 张浩 on 2023/10/12.
//

#import "NSArray+MM_AY.h"

@implementation NSArray (MM_Partition)

/**
 数组按几个一起分割
 
 @param count 个数
 @return 分割后的数组
 */
- (NSMutableArray *)PartitionWithCount:(NSInteger)count {
  //每个个数
  NSString * sl = [NSString stringWithFormat:@"%ld",count];
  
  //分成几个数组Model
  NSInteger partitionCount = ceilf(self.count/sl.floatValue);
  
  NSMutableArray * returnArr = [[NSMutableArray alloc]init];
  
  for (int i = 0; i < partitionCount; i++) {
    
      MM_CellArrModel * pArrModel = [[MM_CellArrModel alloc]init];
    
    NSIndexSet * set = [[NSIndexSet alloc]initWithIndexesInRange:NSMakeRange(i * count,i == partitionCount - 1? self.count - i * count:count)];
    
    pArrModel.cellArr = [self objectsAtIndexes:set];
    
    [returnArr addObject:pArrModel];
  }
  
  return returnArr;
}

@end

@implementation NSArray (MM_AY)

- (id)objectAt:(NSInteger)index
{
    if (index < self.count && index >= 0) {
        return self[index];
    }else
    {
        return nil;
    }
}

/**@Lee
 *  根据数组找到当前的Vc 类
 *
 *  @param classStr 类的字符串
 *
 *  @return 控制器
 */
- (UIViewController *)findVCWithClassStr:(NSString *)classStr {
    
    for (UIViewController * vc in self) {
        if ([vc isKindOfClass:[UIViewController class]]) {
            if ([vc isKindOfClass:NSClassFromString(classStr)]) {
                
                return vc;
            }
        }
    }
    return nil;
}

@end


@implementation NSMutableArray (AddOBJ)

/**
 *  其实这个方法是 因为在ios7 和 ios8 中系统的这个方法 有些不一样
 *
 *  @param otherArray 其他的数组
 */
- (void)addObjectsFrom_MyArr:(NSArray *)otherArray{
    if ([otherArray isKindOfClass:[NSArray class]]) {
        for (id model in otherArray) {
            [self addObject:model];
        }
    }
}

//- (NSMutableArray *)jh_objectsAtIndexes:(NSMutableArray*)arr length:(NSInteger)lentgh {
//    //布局cell个数
//    NSString * sl = [NSString stringWithFormat:@"%ld",lentgh];
//
//    NSInteger freeCount = ceilf(arr.count/sl.floatValue);
//
//    NSMutableArray * returnArr = [[NSMutableArray alloc]init];
//
//    for (int i = 0; i < freeCount; i++) {
//        JH_CellArrModel * cellFreeModel = [[JH_CellArrModel alloc]init];
//        NSIndexSet * set = [[NSIndexSet alloc]initWithIndexesInRange:NSMakeRange(i * lentgh,i == freeCount - 1? arr.count - i * lentgh:lentgh)];
//
//        cellFreeModel.cellArr = [arr objectsAtIndexes:set];
//        cellFreeModel.tempArr = arr;
//
//        [returnArr addObject:cellFreeModel];
//    }
//
//    return returnArr;
//}
@end
